//
//  StellWeightComintTableViewCell.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/22.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "StellWeightComintTableViewCell.h"

@interface StellWeightComintTableViewCell ()
@property (nonatomic,strong) GLGWLabel * unitlabel;
@end

@implementation StellWeightComintTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        GLGWButton * comintBut = [[GLGWButton alloc] initWithTitle:@"计算" titleLableFont:SYSTEMFONT(14) titleLableColor:[UIColor whiteColor] theCornerRadius:kHeightProportion_In_iPhoneTriploid(22) backgroundColr:kColor_Rule_Yellow inSuperView:self.contentView];
        [comintBut addTarget:self action:@selector(jiSuanAction) forControlEvents:UIControlEventTouchUpInside];
        [comintBut mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.contentView.mas_bottom).offset(0);
            make.left.equalTo(self.contentView.mas_left).offset(kWidthProportion_In_iPhoneTriploid(15));
            make.right.equalTo(self.contentView.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(44)));
        }];
        //
        self.unitlabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(14) theColor:[UIColor colorWithHexString:@"#EC5353"] inSuperView:self.contentView];
        self.unitlabel.textAlignment = NSTextAlignmentRight;
        [self.unitlabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15));
            make.top.equalTo(self.contentView.mas_top).offset(kHeightProportion_In_iPhoneTriploid(32));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(20)));
        }];
        
        GLGWLabel * jieGuoLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(14) theColor:[UIColor colorWithHexString:@"#666666"] inSuperView:self.contentView];
        jieGuoLabel.text = @"计算结果：";
        [jieGuoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.unitlabel.mas_left).offset(0);
            make.top.equalTo(self.unitlabel);
            make.height.equalTo(self.unitlabel);
        }];
    }
    return self;
}

-(void)setCai_type:(CaiculatorType)cai_type{
    _cai_type = cai_type;
    [self chuShiHua];
}

-(void)chuShiHua{
    if (_cai_type == CaiculatorType_Weight) {
        self.unitlabel.attributedText = [GLGWLabel bllChangeStr:@"0.0000 吨" changewithStr:@"吨" changeColoer:[UIColor colorWithHexString:@"#999999"] withFont:SYSTEMFONT(14)];
    }else{
        self.unitlabel.attributedText = [GLGWLabel bllChangeStr:@"0.0000 m" changewithStr:@"m" changeColoer:[UIColor colorWithHexString:@"#999999"] withFont:SYSTEMFONT(14)];
    }
}

-(void)setUnitNum:(double)unitNum{
    _unitNum = unitNum;
    if (_unitNum == 0) {
        [self chuShiHua];
        return;
    }
    NSString * unste;
    if (_cai_type == CaiculatorType_Weight) {
        unste = [NSString stringWithFormat:@"%.4f 吨",_unitNum];
        self.unitlabel.attributedText = [GLGWLabel bllChangeStr:unste changewithStr:@"吨" changeColoer:[UIColor colorWithHexString:@"#999999"] withFont:SYSTEMFONT(14)];
    }else{
        unste = [NSString stringWithFormat:@"%.4f m",_unitNum];
        self.unitlabel.attributedText = [GLGWLabel bllChangeStr:unste changewithStr:@"m" changeColoer:[UIColor colorWithHexString:@"#999999"] withFont:SYSTEMFONT(14)];
    }
    
}

-(void)jiSuanAction{
    kKeyboardEndEditing
    if (self.Block_StellJiSuan) {
        self.Block_StellJiSuan();
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
